//! PlayNexus.debug.js
//

(function() {

Type.registerNamespace('PlayNexus.Classes');

////////////////////////////////////////////////////////////////////////////////
// BasicPage

BasicPage = function BasicPage() {
    /// <field name="fbData" type="FbDataStore" static="true">
    /// </field>
    /// <field name="_gigShow$5" type="GigShow" static="true">
    /// </field>
    /// <field name="pageFooter" type="jQueryObject">
    /// </field>
    /// <field name="pageMaster" type="jQueryObject">
    /// </field>
    /// <field name="_focusElement$5" type="jQueryObject">
    /// </field>
    BasicPage.initializeBase(this);
    this.set_title('Yoshi Page');
    this.pageMaster = $('#' + Master.pageMasterId);
    Inform.log('Creating page instance FullClass={0}, PageName={1}', Type.getInstanceType(this).get_fullName(), ThemeBase.currentPageName);
    if (Await.files['Pages'] == null) {
        new Await().loadJson('Pages', Uri.join(ThemeBase.dataPath, ThemeBase.pagesPartition, ThemeBase.pagesRowKey + '.txt')).handleDl(Exceptions.blobLoadError, Await.ignoreAw).addDx(function() {
            ThemeBase.pages = Await.files['Pages'];
        }).commit();
    }
}
BasicPage.curateAw = function BasicPage$curateAw(awp, curateElement) {
    /// <param name="awp" type="Await">
    /// </param>
    /// <param name="curateElement" type="jQueryObject">
    /// </param>
    var curating = Nsb.Storage.getLocal(ThemeBase.curatingKey);
    curateElement.empty();
    var slideControls = $("<div class='SlideControls'/>").appendTo(curateElement);
    var gigLib = Uri.versionize('Scripts/WhirliGig.debug.js');
    var gigLibEd = Uri.versionize('Scripts/WhirliGigEdit.debug.js');
    if (curating) {
        $('#PageContent').addClass('PageEdge');
    }
    var awx = new Await().loadText('ColorPickerTable', 'Scripts/Data/GigColorPicker.html');
    if (curating) {
        awx.loadScript(gigLib).loadScript(gigLibEd, function(aw) {
            if (BasicPage._gigShow$5 != null) {
                BasicPage._gigShow$5.destroy();
            }
            BasicPage._gigShow$5 = (curating) ? new GigShowEdit() : new GigShow();
            BasicPage._gigShow$5.editing = curating;
            BasicPage._gigShow$5.curating = curating;
            BasicPage._gigShow$5.initializeAw(aw, { PartitionKey: 'pg/gigs/' + ThemeBase.currentPageName, RowKey: ThemeBase.curatorId, PageSelectTo: '#PageGigs', PageCssTo: '#' + Master.pageMasterId, SlideControls: slideControls, HasSelect: false, NoSlides: true });
        });
    }
    else {
        awx.loadScript(gigLib, function(aw) {
            if (BasicPage._gigShow$5 != null) {
                BasicPage._gigShow$5.destroy();
            }
            BasicPage._gigShow$5 = (curating) ? new GigShowEdit() : new GigShow();
            BasicPage._gigShow$5.editing = curating;
            BasicPage._gigShow$5.curating = curating;
            BasicPage._gigShow$5.initializeAw(aw, { PartitionKey: 'pg/gigs/' + ThemeBase.currentPageName, RowKey: ThemeBase.curatorId, PageSelectTo: '#PageGigs', PageCssTo: '#' + Master.pageMasterId, SlideControls: slideControls, HasSelect: false, NoSlides: true });
        });
    }
    awx.addDl(function(aw) {
        BasicPage._gigShow$5.restoreAw(aw);
    }).commit(awp);
}
BasicPage.prototype = {
    pageFooter: null,
    pageMaster: null,
    _focusElement$5: null,
    
    get_title: function BasicPage$get_title() {
        /// <value type="String"></value>
        return document.title;
    },
    set_title: function BasicPage$set_title(value) {
        /// <value type="String"></value>
        document.title = value;
        return value;
    },
    
    updatePage: function BasicPage$updatePage(pu) {
        /// <param name="pu" type="PageUpdate">
        /// </param>
    },
    
    focusEvent: function BasicPage$focusEvent(e) {
        /// <param name="e" type="jQueryEvent">
        /// </param>
        this._focusElement$5 = (ss.isValue(e)) ? $(e.target) : null;
    },
    
    isFocused: function BasicPage$isFocused(el) {
        /// <param name="el" type="jQueryObject">
        /// </param>
        /// <returns type="Boolean"></returns>
        return this._focusElement$5 != null && el[0] === this._focusElement$5[0];
    },
    
    destroy: function BasicPage$destroy() {
    },
    
    basicBuildAw: function BasicPage$basicBuildAw(awp) {
        /// <param name="awp" type="Await">
        /// </param>
        new Await().addDl(function(aw) {
            try {
                var tst = ThemeBase.pages.pages[ThemeBase.currentPageName].Name.length > 0;
                aw.done();
            }
            catch ($e1) {
                Master.log(String.format('Failed to load page "{0}"', ThemeBase.currentPageName), window.location.href, 0);
                window.setTimeout(function() {
                    Nsb.Storage.setSession(ThemeBase.pageAttrKey, ThemeBase.defaultPageClass);
                    Nsb.Storage.setSession(ThemeBase.pageNameKey, ThemeBase.defaultPageName);
                    if (ThemeBase.currentPageName !== ThemeBase.defaultPageName) {
                        ThemeBase.reloadPage();
                    }
                }, 1);
                aw.abort();
            }
        }).addDx(ss.Delegate.create(this, function() {
            Inform.debug('BasicBuildAw');
            var centerBox = $("<div id='PageCenter'/>").appendTo(this.pageMaster);
            this.element = $("<div id='PageContent'/>").appendTo(centerBox).addClass(Type.getInstanceType(this).get_name());
            this.set_title(ThemeBase.get_currentPage().Title || ThemeBase.get_currentPage().Face || ThemeBase.get_currentPage().Name);
        })).addFn(ss.Delegate.create(this, this.basicCluster)).addFn(ss.Delegate.create(this, this.basicFooter)).addAw(ss.Delegate.create(this, this.refreshAw)).addAw(ss.Delegate.create(this, this.pageAw)).addDx(function() {
            FileBlobBase.svCnt--;
        }).commit(awp);
    },
    
    refreshAw: function BasicPage$refreshAw(awp) {
        /// <param name="awp" type="Await">
        /// </param>
        awp.done();
    },
    
    pageAw: function BasicPage$pageAw(awp) {
        /// <param name="awp" type="Await">
        /// </param>
        var curateEl = $('#CurateElement');
        if (!curateEl.length) {
            curateEl = $("<div id='CurateElement'/>").appendTo(document.body);
        }
        BasicPage.curateAw(awp, curateEl);
    },
    
    basicCluster: function BasicPage$basicCluster() {
        $("<div id='PageGigs' class='FrontContent'/>").appendTo(this.element);
    },
    
    basicFooter: function BasicPage$basicFooter() {
        this.pageFooter = $("<div class='PageFooter'/>").appendTo(this.element).html('');
    },
    
    showTopUser: function BasicPage$showTopUser() {
    },
    
    loadPageCssAw: function BasicPage$loadPageCssAw(awp) {
        /// <param name="awp" type="Await">
        /// </param>
        new Await().loadCss('Scripts/Css/' + Type.getInstanceType(this).get_name() + '.css').commit(awp);
    },
    
    loadNamespaceCssAw: function BasicPage$loadNamespaceCssAw(awp) {
        /// <param name="awp" type="Await">
        /// </param>
        new Await().loadCss('Scripts/Css/' + Type.getInstanceType(this).get_fullName().split('.')[0] + '.css').commit(awp);
    }
}


////////////////////////////////////////////////////////////////////////////////
// Build

Build = function Build() {
    /// <field name="sendTo" type="String" static="true">
    /// </field>
}
Build.ComePlay = function Build$ComePlay() {
    $('.SubmitEmail button').click(function() {
        var mail = {};
        var smd = mail;
        smd.to = Build.sendTo;
        smd.subject = 'Come Play Request!';
        smd.from = $('.EmailFrom input[type=text]').getFValueString().trim();
        var content = 'From: ' + $('.EmailName input[type=text]').getFValueString().trim() + '<br><br>';
        smd.content = content + '<p>' + $('.EmailContent textarea').getFValueString().trim() + '</p>';
        Build._sendTheMail(mail);
    });
    Build._initializePageInput();
}
Build.HomePage = function Build$HomePage() {
    $('.SubmitRequest button').click(function() {
        var mail = {};
        var smd = mail;
        smd.to = Build.sendTo;
        var from = $('.Email input[type=text]').getFValueString().trim();
        smd.subject = 'PlayNexus - News Letter Request';
        smd.from = from;
        var content = 'From: ' + from + '<br>';
        smd.content = content + '<p>Please add me to your news letter &#9786;</p>';
        Build._sendTheMail(mail);
    });
    Build._initializePageInput();
}
Build.ScheduleSalon = function Build$ScheduleSalon() {
    $('.ScheduleSalon button').click(function() {
        new Ask().okAw(Await.get_asyncAw(), 'Feature coming soon.<br>Try again tomorrow! ' + ThemeBase.hearts);
    });
    Build._initializePageInput();
}
Build._sendTheMail = function Build$_sendTheMail(mail) {
    /// <param name="mail" type="Object">
    /// </param>
    new Await().addAw(CloudMail.sendMailAw, mail).addDx(function() {
        Ask.ok('Your request has been received.<br><br>&nbsp;&nbsp;&nbsp;&nbsp;Thank you!');
    }).commit();
}
Build._initializePageInput = function Build$_initializePageInput() {
    var gigs = $('#PageGigs');
    $('input[type=text],textarea', gigs).each(function(i, domEl) {
        var ths = $(domEl);
        ths.attr('title', ths.val());
        ths.focus(function(e) {
            var el = $(e.target);
            var title = el.attr('title');
            if (el.val().trim() === title) {
                el.val('');
            }
        });
        ths.blur(function(e) {
            var el = $(e.target);
            if (String.isNullOrEmpty(el.val().trim())) {
                el.val(el.attr('title'));
            }
        });
    });
}
Build.BuildAction = function Build$BuildAction(action) {
    /// <param name="action" type="String">
    /// </param>
    if (action != null) {
        try {
            eval(action + '()');
        }
        catch (ex) {
            Inform.error('Slide build error: {0}', ex);
        }
    }
}


////////////////////////////////////////////////////////////////////////////////
// FunctionKeys

FunctionKeys = function FunctionKeys() {
    /// <field name="_askingCurate" type="Boolean" static="true">
    /// </field>
}
FunctionKeys.F2 = function FunctionKeys$F2(e, keyEv) {
    /// <param name="e" type="jQueryEvent">
    /// </param>
    /// <param name="keyEv" type="jQueryEvent">
    /// </param>
    if (FunctionKeys._askingCurate) {
        return;
    }
    e = keyEv || e;
    DomElement.cancelEvent(e);
    if (e.shiftKey) {
        Nsb.Storage.removeLocal('CuratePassword');
        Nsb.Storage.removeLocal('Curating');
        Nsb.Storage.removeSession('Editing');
    }
    var curating = Nsb.Storage.getLocal('Curating');
    if (curating) {
        Nsb.Storage.setLocal('Curating', false);
        FunctionKeys._goThere();
    }
    else {
        var password = Nsb.Storage.getLocal('CuratePassword');
        if (String.isNullOrEmpty(password)) {
            FunctionKeys._askingCurate = true;
            new Await().addAw(ss.Delegate.create(new Ask(), new Ask().textAw), { Msg: 'Curation Password', Value: '' }).addDx(function() {
                FunctionKeys._askingCurate = false;
            }).addAw(DomElement.requireResultAw, DomElement.notFailOrEmpty).addDx(function(aw) {
                Nsb.Storage.setLocal('CuratePassword', aw.get_item(PkgBase.resultRx));
                Nsb.Storage.setLocal('Curating', true);
                FunctionKeys._goThere();
            }).commit();
        }
        else {
            Nsb.Storage.setLocal('Curating', true);
            FunctionKeys._goThere();
        }
    }
}
FunctionKeys._goThere = function FunctionKeys$_goThere() {
    if (!ThemeBase.dynamicPaging) {
        Uri.bumpVersion();
        var filebase = Uri.removeExt(Uri.end(window.location.href));
        Nsb.Storage.setSession(ThemeBase.pageAttrKey, ThemeBase.defaultPageClass);
        Nsb.Storage.setSession(ThemeBase.pageNameKey, filebase);
        window.location.href = ThemeBase.masterPage;
    }
    else {
        ThemeBase.reloadPage();
    }
}


////////////////////////////////////////////////////////////////////////////////
// VirtualPage

VirtualPage = function VirtualPage() {
    VirtualPage.initializeBase(this);
    new Await().waitDx(function() {
        return ThemeBase.pages != null;
    }, 30000).addAw(ss.Delegate.create(this, this.basicBuildAw)).commit();
}
VirtualPage.prototype = {
    
    refreshAw: function VirtualPage$refreshAw(awp) {
        /// <param name="awp" type="Await">
        /// </param>
        awp.done();
    }
}


Type.registerNamespace('PlayNexus.Clusters');

////////////////////////////////////////////////////////////////////////////////
// Links

Links = function Links(options) {
    /// <param name="options" type="Object">
    /// </param>
    /// <field name="_options$2" type="Object">
    /// </field>
    Links.initializeBase(this);
    this.element = $("<div id='TopBar' style='position: relative; width: 100%; height: 100%; display: block;'/>");
    this._options$2 = options || { links: true };
}
Links.newLink = function Links$newLink(face, pageClass, pageName) {
    /// <param name="face" type="String">
    /// </param>
    /// <param name="pageClass" type="String">
    /// </param>
    /// <param name="pageName" type="String">
    /// </param>
    /// <returns type="jQueryObject"></returns>
    var lnk = $('<a/>').attr('href', 'javascript:;').html(Transform.htmlize(face)).swallowClick(function() {
        Master.GoPage(pageClass, pageName);
    });
    if (ThemeBase.currentPageName === pageName) {
        lnk.addClass('CurrentPage');
    }
    return lnk;
}
Links.prototype = {
    _options$2: null,
    
    Content: function Links$Content() {
        /// <returns type="jQueryObject"></returns>
        new Await().waitDx(function() {
            return ThemeBase.pages != null;
        }, 30000).addFn(ss.Delegate.create(this, this._build$2)).commit();
        return this.element;
    },
    
    _build$2: function Links$_build$2() {
        if (this._options$2['links']) {
            var $dict1 = ThemeBase.pages.pages;
            for (var $key2 in $dict1) {
                var pg = { key: $key2, value: $dict1[$key2] };
                if (!pg.value.Visible) {
                    continue;
                }
                var linkFace = pg.value.Face || pg.value.Name;
                var pageClass = pg.value.Class || 'VirtualPage';
                var pageName = pg.value.Name || 'Page';
                Links.newLink(linkFace, pageClass, pageName).appendTo(this.element).addClass('BarLink');
            }
        }
    }
}


BasicPage.registerClass('BasicPage', ProfileTruple, IPage);
Build.registerClass('Build');
FunctionKeys.registerClass('FunctionKeys');
VirtualPage.registerClass('VirtualPage', BasicPage);
Links.registerClass('Links', Cluster);
BasicPage.fbData = new FbDataStore();
BasicPage._gigShow$5 = null;
Build.sendTo = window.localStorage.getItem('AltEmailTo') || 'natalie.kinsey@gmail.com';
FunctionKeys._askingCurate = false;
})();

//! This script was generated using Script# v0.7.4.0
